package com.itheima.hello.hellopromax高级进阶.休息日;

import java.io.FileNotFoundException;
import java.time.Duration;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Scanner;

public class test {
    public static void main(String[] args) throws FileNotFoundException {
        LocalDate startDate = LocalDate.of(2022,2,3);//2023-02-03为起始休息日
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你要查询的年份和月份，以便为你展示该月休息日(注意，必须是2022-02月开始或者之后: )");
        String nowdate1 = sc.next();//2023-02
        String nowdate = nowdate1 + "-01";//由于后面的格式化要求必须输入格式为年月日的形式，所以拼接一个日期--> 2023-02-01
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate endDate = LocalDate.parse(nowdate,dtf);//2023-02-01
//        System.out.println(endDate);
        //由于输入的年月是随机的，不能提前确定输入月到底是28天，29天，30天，31天，这样不好处理
        //把输入的日期解析然后再把解析后的日期加一个月再减一天就是该输入日期月份的最后一天
        LocalDate endOfMonth = endDate.plusMonths(1).minusDays(1);//2023-02-28
//        System.out.println(endOfMonth);
        ArrayList<day> d = new ArrayList();
        while (!startDate.isAfter(endOfMonth)){
            day days = new day(startDate);
            //把日期对象假日集合
            d.add(days);
            //每加一天就创建一个新对象
            startDate = startDate.plusDays(1);
        }
//        System.out.println(d);
        System.out.println("历史全部休息日如下:");
        for (int i = 0; i < d.size(); i += 3) {
            d.get(i).setFlag(true);//标记全部休息日
            System.out.print(d.get(i).getDay() + (d.get(i).isFlag()?"[休息] ":" "));
        }
        ArrayList<day> workOrRest = new ArrayList<>(); //用来当月的休息日以及工作日的集合
        System.out.println();
        System.out.println(nowdate1 + "当月的休息日情况如下:");
        for (int i = 0; i < d.size(); i++) {
            day day = d.get(i);
            if (day.getDay().isBefore(endDate)){
                continue;
            }else {
                workOrRest.add(day); //把endDate开始的日子至该月末的对象已添加进去
                System.out.print(day.getDay() + (day.isFlag()?"[休息] ":" "));
            }}
        System.out.println();
        System.out.println(nowdate1 + "当月休息日是周末的情况如下:");
        for (int i = 0; i < workOrRest.size(); i++) {
            day day = workOrRest.get(i);
            int value = day.getDay().getDayOfWeek().getValue();
            if (value == 6){
                if (day.isFlag()){
                System.out.print(day.getDay() + "[休息(周六)]");
            }}
            if (value == 7){
                if (day.isFlag()){
                    System.out.print(day.getDay() + "[休息(周日)]");
            }}
        }}}





